﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace WarehouseManagement.BusinessLogic.DTO
{
    public partial class PODetailDTO : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private System.Guid _Id;

        private int _MerchandiseId;

        private double _Quantity;

        private decimal _UnitPrice;

        private double _Tax;

        private decimal _ShippingFee;

        //private System.Nullable<double> _UnitPriceAfterTax;

        private System.Guid _POId;

      

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(System.Guid value);
        partial void OnIdChanged();
        partial void OnMerchandiseIdChanging(int value);
        partial void OnMerchandiseIdChanged();
        partial void OnQuantityChanging(double value);
        partial void OnQuantityChanged();
        partial void OnUnitPriceChanging(decimal value);
        partial void OnUnitPriceChanged();
        partial void OnTaxChanging(double value);
        partial void OnTaxChanged();
        partial void OnShippingFeeChanging(decimal value);
        partial void OnShippingFeeChanged();
        partial void OnUnitPriceAfterTaxChanging(System.Nullable<double> value);
        partial void OnUnitPriceAfterTaxChanged();
        partial void OnPOIdChanging(System.Guid value);
        partial void OnPOIdChanged();
        #endregion

        public PODetailDTO()
        {
           
            OnCreated();
            Id = Guid.NewGuid();
            this.Quantity = 1;
        }

        public System.Guid Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }

        public int MerchandiseId
        {
            get
            {
                return this._MerchandiseId;
            }
            set
            {
                if ((this._MerchandiseId != value))
                {
                   
                    this.OnMerchandiseIdChanging(value);
                    this.SendPropertyChanging();
                    this._MerchandiseId = value;
                    this.SendPropertyChanged("MerchandiseId");
                    this.OnMerchandiseIdChanged();
                }
            }
        }
        public string MerchandiseUnit { get; set; }
        public string MerchandiseName { get; set; }
        public string MerchandiseCategory { get; set; }
        public double Quantity
        {
            get
            {
                return this._Quantity;
            }
            set
            {
                if ((this._Quantity != value))
                {
                    this.OnQuantityChanging(value);
                    this.SendPropertyChanging();
                    this._Quantity = value;
                    this.SendPropertyChanged("Quantity");
                    this.OnQuantityChanged();
                }
            }
        }

        public decimal UnitPrice
        {
            get
            {
                return this._UnitPrice;
            }
            set
            {
                if ((this._UnitPrice != value))
                {
                    this.OnUnitPriceChanging(value);
                    this.SendPropertyChanging();
                    this._UnitPrice = value;
                    this.SendPropertyChanged("UnitPrice");
                    this.OnUnitPriceChanged();
                }
            }
        }

        public double Tax
        {
            get
            {
                return this._Tax;
            }
            set
            {
                if ((this._Tax != value))
                {
                    this.OnTaxChanging(value);
                    this.SendPropertyChanging();
                    this._Tax = value;
                    this.SendPropertyChanged("Tax");
                    this.OnTaxChanged();
                }
            }
        }

        public decimal ShippingFee
        {
            get
            {
                return this._ShippingFee;
            }
            set
            {
                if ((this._ShippingFee != value))
                {
                    this.OnShippingFeeChanging(value);
                    this.SendPropertyChanging();
                    this._ShippingFee = value;
                    this.SendPropertyChanged("ShippingFee");
                    this.OnShippingFeeChanged();
                }
            }
        }

        //public System.Nullable<double> UnitPriceAfterTax
        //{
        //    get
        //    {
        //        return this._UnitPriceAfterTax;
        //    }
        //    set
        //    {
        //        if ((this._UnitPriceAfterTax != value))
        //        {
        //            this.OnUnitPriceAfterTaxChanging(value);
        //            this.SendPropertyChanging();
        //            this._UnitPriceAfterTax = value;
        //            this.SendPropertyChanged("UnitPriceAfterTax");
        //            this.OnUnitPriceAfterTaxChanged();
        //        }
        //    }
        //}
        public decimal ExchangeRate { get; set; }

        public System.Guid POId
        {
            get
            {
                return this._POId;
            }
            set
            {
                if ((this._POId != value))
                {
                   
                    this.OnPOIdChanging(value);
                    this.SendPropertyChanging();
                    this._POId = value;
                    this.SendPropertyChanged("POId");
                    this.OnPOIdChanged();
                }
            }
        }

        public PODTO PO { get; set; }
        public decimal TotalUnitPrice
        {
            get
            {
                return UnitPriceAfterTax * (decimal)Quantity * ExchangeRate;
            }

        }

        public decimal UnitPriceAfterTax
        {
            get
            {
                return (UnitPrice + ((decimal)Tax / 100 * UnitPrice) + ShippingFee);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
